import './App.css';
import React from 'react';
import { Toast } from 'antd-mobile';
import { connect } from 'react-redux';
import * as request from './request';
import LineRadar from './LineRadar';

const apiURL = "/api/services/app/Edu_Children/Get?id=";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            babyData: {
                name: '',
                birthday: '2020-1-1'
            },
            dataSource: [],
            dataDtl: [],
            open: false,
            title: '儿童评测',
            score: 0,
            modal1: false,
            initialPage: 0,
        }
    }
    componentDidMount() {
        this.fetchData();
    }
    fetchData = () => {
        var cid = this.props.match.params.childid;
        this.getBabyData(cid)
    }
    getBabyData = (cid) => {
        if (cid) {
            Toast.loading('Loading...', 0);
            request.get(apiURL + cid)
                .then((data) => {
                    if (data.result) {
                        this.setState({ babyData: data.result })
                    }
                    Toast.hide();
                })
                .catch((error) => {
                    console.log('fetch data failed', error);
                });
        }
    }
    render() {
        const { babyData } = this.state;
        return (
            <div>
                <LineRadar babyData={babyData} />
            </div>
        )
    };
}

export default connect(
    state => ({ currentUser: state.setCurrentUser, currentChild: state.setCurrentChild })
)(App)
